package cn.liziguo.tank.collision;

import cn.liziguo.tank.config.GameConfig;
import cn.liziguo.tank.constants.GameEnum;
import cn.liziguo.tank.constants.ItemType;
import cn.liziguo.tank.constants.PropertyConst;
import cn.liziguo.tank.factory.MapFactory;
import cn.liziguo.tank.script.enemy.EnemyComponent;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;

/**
 * @author Liziguo
 * @date 2022-07-09 21:26:11
 */
public class ItemEnemyCollisionHandler extends CollisionHandler {

    public ItemEnemyCollisionHandler() {
        super(GameEnum.ITEM, GameEnum.ENEMY);
    }

    @Override
    protected void onCollisionBegin(Entity item, Entity player) {
        // 让道具消失
        item.removeFromWorld();
        // 拿到PlayerComponent
        final EnemyComponent enemyComponent = player.getComponent(EnemyComponent.class);
        // 从entity获得道具类型
        final ItemType type = item.getObject(PropertyConst.ITEM_TYPE);
        switch (type) {
            // 吃到星星道具
            case STAR -> enemyComponent.bulletLevelUp();
            // 吃到枪道具
            case GUN -> enemyComponent.bulletLevel = GameConfig.BULLET_LEVEL_MAX;
            // 吃到爱心道具
            case HEART -> enemyComponent.restore(GameConfig.ITEM_HEART);
            // 吃到船道具
            case SHIP -> enemyComponent.giveArmedShip();
            // 吃到计时器道具
            case TIME -> {}
            // 吃到头盔道具
            case HELMET -> enemyComponent.giveInvincible();
            // 吃到坦克道具
            case TANK -> enemyComponent.giveSpeeding();
            // 吃到炸弹道具
            case BOMB -> enemyComponent.skillCount++;
            // 吃到铁铲道具
            case SPADE -> {
                MapFactory.clearHomeFence();
            }
        }

    }
}
